package alittlepond.config;

public class PropertySpec {

	public static final int INT_DEFAULT_MAX = 100;
	public static final int INT_DEFAULT_MIN = 0;
	public static final int INT_DEFAULT_STEP = 1;
		
	public static final double DOUBLE_DEFAULT_MIN = 0.0;
	public static final double DOUBLE_DEFAULT_MAX = 1.0;
	public static final double DOUBLE_DEFAULT_STEP = 0.01;
	
	
		private String title;
		private PropertyType propertyType;
		private Object defaultValue;
		private Number minValue, maxValue, stepSize;
		
		 public String getTitle() { return title; }
		 public PropertyType getPropertyType() { return propertyType; }
		 public Object getDefaultValue() { return defaultValue; }

		 
		public Number getMinValue() { return minValue; }
		public Number getMaxValue() { return maxValue; }
		public Number getStepSize() { return stepSize; }
		
		public static PropertySpec prop(String title, PropertyType propertyType, Object defaultValue) {
			return new PropertySpec(title, propertyType, defaultValue);
		}
		private PropertySpec(String title, PropertyType propertyType, Object defaultValue) 
		{ 
			this.title = title; 
			this.propertyType = propertyType; 
			this.defaultValue = defaultValue; 
		
			//TODO: type checking here.
			switch (propertyType) {
			case BOOLEAN:
				
				break;

			case DOUBLE: {
				double def = (Double) defaultValue; //also does validation.
				
				minValue = Math.min(def,DOUBLE_DEFAULT_MIN);
				maxValue = Math.max(def, DOUBLE_DEFAULT_MAX);
				stepSize = DOUBLE_DEFAULT_STEP;
				break;}
			case INT:{
				int def = (Integer) defaultValue;
				
				minValue = Math.min(def, INT_DEFAULT_MIN);
				maxValue = Math.max(def, INT_DEFAULT_MAX);
				stepSize = INT_DEFAULT_STEP;
				break;}
			default:
				break;
			}
		}
		

		public static PropertySpec prop(String title, int defaultValue, int min, int max, int step) {
			return new PropertySpec(title, defaultValue, min, max, step);
		}
		private PropertySpec(String title,int defaultValue, int min, int max, int step) 
		{ 
			//TODO: validation here.
			this.title = title; 
			this.propertyType = PropertyType.INT; 
			this.defaultValue = defaultValue; 
			this.minValue = min;
			this.maxValue = max;
			this.stepSize = step;
		}
		
		public static PropertySpec prop(String title, double defaultValue, double min, double max, double step) {
			return new PropertySpec(title, defaultValue, min, max, step);
		}
		private PropertySpec(String title,double defaultValue, double min, double max, double step) 
		{ 
			//TODO: validation here.
			this.title = title; 
			this.propertyType = PropertyType.DOUBLE; 
			this.defaultValue = defaultValue; 
			this.minValue = min;
			this.maxValue = max;
			this.stepSize = step;
		}
		
		
}
